package com.kefu.call.listener;

import com.kefu.call.http.client.CtiClient;
import com.kefu.call.http.model.CtiBlackPhone;
import com.kefu.call.http.model.CtiResult;
import com.kefu.crm.event.CrmCustomerEvent;
import com.kefu.crm.model.CrmCustomer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CallListener {
    @Autowired
    private CtiClient ctiClient;

    @EventListener(CrmCustomerEvent.class)
    public void crmCustomerBlackEvent(CrmCustomerEvent event) {
        CrmCustomer crmCustomer = event.getCrmCustomer();
        CtiBlackPhone param = new CtiBlackPhone();
        param.setPhone(crmCustomer.getPhone());
        param.setCompany(crmCustomer.getTenantId());
        switch (crmCustomer.getCustomerStatus()) {
            case 1 : {
                CtiResult callResult = ctiClient.blacklistDel(param);
                log.info("同步呼叫fs服务删除黑名单返回信息 : {},{}", crmCustomer.getPhone(), callResult);
            }
            break;
            case 3 : {
                CtiResult callResult = ctiClient.blacklistAdd(param);
                log.info("同步呼叫fs服务添加黑名单返回信息 : {},{}", crmCustomer.getPhone(), callResult);
            }
        }
    }
}
